#include <QDebug>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QFileInfo>
#include <QPluginLoader>


void testLoadPlugin(const char *filepath) {
    qInfo() << "=============================================";
    qInfo() << "try load plugin: " << filepath;
    QFileInfo fileinfo(filepath);
    qInfo() << "file exists: " << fileinfo.exists() << ", file size: " << fileinfo.size()
            << ", readable: " << fileinfo.isReadable();
    QPluginLoader *loader = new QPluginLoader(fileinfo.absoluteFilePath());
    if (!loader->load()) {
        qWarning() << "load error: " << loader->errorString();
    }
    qInfo() << "=============================================";
}

int main(int argc, char *argv[]) {
    QGuiApplication app(argc, argv);
    qputenv("QT_DEBUG_PLUGINS", QByteArray("1"));
    qInfo() << "Hello, Qt For OpenHarmony!";

//     testLoadPlugin("/data/storage/el2/base/cache/Qt/qml/QtQuick.2/libqtquick2plugin.so");
//     testLoadPlugin("/data/storage/el2/base/cache/Qt/qml/QtQuick/Window.2/libwindowplugin.so");
//     testLoadPlugin("/data/storage/el2/base/cache/Qt/qml/QtQml/libqmlplugin.so");

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/dist/main.qml"));
    QObject::connect(
        &engine, &QQmlApplicationEngine::objectCreated, &app,
        [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        },
        Qt::QueuedConnection);
    engine.load(url);
    return app.exec();
}